﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace test5_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Display(Shape s)
        {
            Labelshow.Text = "体积为：" + s.Cubage();
        }
        public abstract class Shape
        {
            protected double radius;
            public Shape(double r) { radius = r; }  //构造函数
            public abstract double Cubage();  //声明抽象方法

        }
        public class Globe : Shape  //定义派生类Globe（圆球体）
        {
            public Globe(double r) : base(r) { } //构造函数
            public override double Cubage()//重写抽象方法
            {
                return 3.14 * radius * radius * radius * 4.0 / 3; ;
            }
        }
        public class Cone : Shape //定义派生类Cone（圆锥体）
        {
            private double high;
            public Cone(double r, double h) : base(r) { high = h; }
            public override double Cubage()//重写抽象方法
            {
                return 3.14 * radius * radius * high / 3;
            }
        }
        public class Cylinder : Shape//定义派生类Cylinder（圆柱体）
        {
            private double high;
            public Cylinder(double r, double h) : base(r) { high = h; }
            public override double Cubage()//重写抽象方法
            {
                return 3.14 * radius * radius * high;
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            double r = Convert.ToDouble(TextR.Text);
            Globe g = new Globe(r);
            Display(g);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            double r = Convert.ToDouble(TextR.Text);
            double h = Convert.ToDouble(TextH.Text);
            Cone co = new Cone(r, h);
            Display(co);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            double r = Convert.ToDouble(TextR.Text);
            double h = Convert.ToDouble(TextH.Text);
            Cylinder cy = new Cylinder(r, h);
            Display(cy);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "胡明辉541901060108";
        }
    }
}
